package com.ithrima.waimaidemo.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ithrima.waimaidemo.common.R;
import com.ithrima.waimaidemo.pojo.Orders;
import com.ithrima.waimaidemo.service.serviceimpl.OrdersServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;



@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrdersServiceImpl ordersService;
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("订单数据：{}",orders);
        ordersService.submit(orders);
        return R.success("下单成功");
    }



    @GetMapping("/page")
    public R<Page> queryByPage( Integer page ,Integer pageSize ){
        Page<Orders> page1 = new Page<>(page,pageSize);
        //LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
       // wrapper.orderByDesc(Orders::getCheckoutTime);
        ordersService.page(page1);
        return R.success(page1);

    }


    @GetMapping("/userPage")
    public R<Page> queryByPage2( Integer page ,Integer pageSize ){
        Page<Orders> page1 = new Page<>(page,pageSize);
        //LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
        // wrapper.orderByDesc(Orders::getCheckoutTime);
        ordersService.page(page1);
        return R.success(page1);

    }
}
